package com.vpen.client.matter;

import cn.hutool.core.util.RandomUtil;
import com.vpen.common.Matter;
import com.vpen.common.Picture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2022/11/25 14:45
 */
@Slf4j
@RestController
@RequestMapping("matter")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class MatterClientController {

    private final MatterClient matterClient;

    @GetMapping("connect")
    public void connect() throws ExecutionException, InterruptedException, TimeoutException {
        matterClient.connect();
    }

    @GetMapping("disconnect")
    public void disconnect() {
        matterClient.disconnect();
    }


    @GetMapping("send")
    public void sendMsg() {
        Matter matter = new Matter();
        List<Picture> list = new ArrayList<>();
        list.add(new Picture().setUrl("baidu.com").setHigh(RandomUtil.randomInt(100, 200)).setWidth(RandomUtil.randomInt(100, 200)));
        list.add(new Picture().setUrl("aliyun.com").setHigh(RandomUtil.randomInt(100, 200)).setWidth(RandomUtil.randomInt(100, 200)));
        matter.setId(RandomUtil.randomLong(100, 200)).setName(RandomUtil.randomString(10)).setPictures(list);
        matterClient.send(matter);
    }
}
